package com.lq.ecoldchain.binding.recycler

import android.databinding.BindingAdapter
import android.support.v4.widget.SwipeRefreshLayout
import android.support.v7.widget.RecyclerView

/*
*2019/1/2 0002  17:44
*function by lq
*/
@BindingAdapter("bind_recycler_adapter")
fun setRecyclerAdapter(view: RecyclerView, adapter: RecyclerView.Adapter<out RecyclerView.ViewHolder>?) {
    view.adapter = adapter
}

@BindingAdapter("onRefreshListener")
fun setOnRefreshListener(swipeRefreshLayout: SwipeRefreshLayout,
                         refreshListener: Runnable?) {
    swipeRefreshLayout.setOnRefreshListener {
        refreshListener?.run()
    }
}

@BindingAdapter("refreshing")
fun isSwipeRefreshLayoutRefreshing(swipeRefreshLayout: SwipeRefreshLayout, newValue: Boolean) {
    if (swipeRefreshLayout.isRefreshing != newValue)
        swipeRefreshLayout.isRefreshing = newValue
}